﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace deFramework.BusinessRules
{
    /// <summary>
    /// 
    /// </summary>
    public class SpEmailTools : Base.BaseBusinessRule
    {

        #region "Constructor, private Variables"

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aContext"></param>
        public SpEmailTools(ref Common.PresentationContext aContext) : base(ref aContext) { }  
 
 
		#endregion


        #region "Email Utilities"

        /// <summary>
        /// 
        /// </summary>
        /// <param name="toAddress"></param>
        /// <param name="fromAddress"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public bool SimpleEmail(string toAddress, string fromAddress, string subject, string body)
        {
            bool _result = false;
            try
            {
                System.Collections.Specialized.StringDictionary headers = this.EmailHeader(
                    toAddress, fromAddress, subject);
                _result = Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
                    this.MyContext.MySpWeb, headers, body);
            }
            catch (Exception ex)
            {
                this.CurrentException = ex;
                this.DebugStatusMessage = "; Exception: " + ex.Message; 
            }
            return _result;
        }

        public string DebugStatusMessage = String.Empty; 

        private System.Collections.Specialized.StringDictionary EmailHeader(string toAddress, string fromAddress, string subject)
        {
            System.Collections.Specialized.StringDictionary headers = new System.Collections.Specialized.StringDictionary();
            headers.Add("to", toAddress);
            headers.Add("from", fromAddress);
            headers.Add("subject", subject);
            return headers;
        }




        #endregion 




    }
}
